//
//  ChooseNumTableViewCell.m
//  shanHaiHuiApp
//
//  Created by DS on 2018/3/14.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "ChooseNumTableViewCell.h"
@interface ChooseNumTableViewCell()<UITextFieldDelegate>

//批号
Strong UILabel * cardLabel;
Strong UILabel * cardDetailLabel;
//库存
Strong UILabel * kucunLabel;
Strong UILabel * kucunDetailLabel;
//到期日
Strong UILabel * dateLabel;
Strong UILabel * dateDetailLabel;

Strong UIView * lineView;




@end

@implementation ChooseNumTableViewCell

- (void)minusBtnClick{
    if(_getMiuteClick){
        
        _getMiuteClick(self,self.textField);
    }
}

- (void)plusBtnClick{
    
    if (_getPlusClick) {
        _getPlusClick(self,self.textField);
    }
}

#pragma mark-- UITextFieldDelegate

- (void)textFieldClick{
    
    
    if (_getTextClik) {
        _getTextClik(self,self.textField);
    }
    
}



- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _cardLabel = [[UILabel alloc] init];
        _cardLabel.text = @"批号-批次";
        _cardLabel.textColor = getColor(textColor);
        _cardLabel.font = DEF_FontSize_11;
        
        _cardDetailLabel = [[UILabel alloc] init];
        _cardDetailLabel.text = @"456789999";
        _cardDetailLabel.textColor = getColor(textColor);
        _cardDetailLabel.font = DEF_FontSize_11;
        
        
        _kucunLabel = [[UILabel alloc] init];
        _kucunLabel.text = @"库存";
        _kucunLabel.textColor = getColor(textColor);
        _kucunLabel.font = DEF_FontSize_11;
        
        _kucunDetailLabel = [[UILabel alloc] init];
        _kucunDetailLabel.text = @"99";
        _kucunDetailLabel.textColor = getColor(textColor);
        _kucunDetailLabel.font = DEF_FontSize_11;
        
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.text = @"到期日";
        _dateLabel.textColor = getColor(textColor);
        _dateLabel.font = DEF_FontSize_11;
        
        _dateDetailLabel = [[UILabel alloc] init];
        _dateDetailLabel.text = @"20190101";
        _dateDetailLabel.textColor = getColor(textColor);
        _dateDetailLabel.font = DEF_FontSize_11;
        
        _chooseLabel = [[UILabel alloc] init];
        _chooseLabel.text = @"选择数量";
        _chooseLabel.textColor = getColor(@"323232");
        _chooseLabel.font = DEF_FontSize_14;
        
        _minusBtn = [[UIButton alloc] init];
        [_minusBtn setImage:[UIImage imageNamed:@"jian"] forState:UIControlStateNormal];
        [_minusBtn addTarget:self action:@selector(minusBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        _plusBtn = [[UIButton alloc] init];
        [_plusBtn setImage:[UIImage imageNamed:@"jia"] forState:UIControlStateNormal];
        [_plusBtn addTarget:self action:@selector(plusBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        _textField = [[UITextField alloc] init];
        _textField.font = DEF_FontSize_14;
        _textField.textColor = getColor(@"323232");
        //_textField.text = @"2";
        _textField.textAlignment = NSTextAlignmentCenter;
        _textField.layer.borderWidth = 1.0f;
        _textField.layer.borderColor = [UIColor grayColor].CGColor;
        _textField.delegate = self;
        //去调用上面的代码，给这个UITextField的对象添加UIToolbar
        _textField.inputAccessoryView = [self addToolbar];
        [_textField addTarget:self action:@selector(textFieldClick) forControlEvents:UIControlEventEditingDidEnd];
        
        
        [self sd_addSubviews:@[self.cardLabel,self.cardDetailLabel,self.dateLabel,self.dateDetailLabel,self.kucunLabel,self.kucunDetailLabel,self.chooseLabel,self.minusBtn,self.plusBtn,self.textField]];
  
        [self layOutFrame];
    }
    return self;
}

- (UIToolbar *)addToolbar
{
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(numberFieldCancle)];
    
    
    toolbar.items = @[space, bar];
    
    return toolbar;
}

- (void)numberFieldCancle{
    
    [self.textField resignFirstResponder];
    
}

- (void)layOutFrame{
    
    ws(self)
    [self.cardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.cardDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.cardLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(weakself.cardLabel.mas_bottom).offset(UNIT_HEIGHT(9));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.dateDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.dateLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.kucunLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(weakself.dateLabel.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.kucunDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.kucunLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.chooseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_HEIGHT(15));
        make.top.mas_equalTo(weakself.kucunLabel.mas_bottom).offset(UNIT_HEIGHT(30));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.plusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.chooseLabel.mas_centerY);
        make.width.mas_equalTo(UNIT_WIDTH(30));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.plusBtn.mas_left).offset(0);
        make.centerY.mas_equalTo(weakself.chooseLabel.mas_centerY);
        make.top.mas_equalTo(weakself.plusBtn.mas_top);
        make.width.mas_equalTo(50);
    }];
    
    [self.minusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.textField.mas_left).offset(0);
        make.centerY.mas_equalTo(weakself.chooseLabel.mas_centerY);
        make.width.mas_equalTo(UNIT_WIDTH(30));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
}

- (void)setModel:(PayMentSpphModel *)model{
    
    _model = model;
    

    self.cardDetailLabel.text = [NSString stringWithFormat:@"%@-%@",model.fPh,model.fPc];
    self.kucunDetailLabel.text = [NSString stringWithFormat:@"%@",model.fSl];
    self.dateDetailLabel.text = [NSString stringWithFormat:@"%@",model.fDqdate];
    
    self.textField.text = [NSString stringWithFormat:@"%@",model.xssl];
    
        if ([model.xssl floatValue] > 0) {
    
            self.minusBtn.hidden = NO;
            self.textField.hidden = NO;
    
        }else{
    
            self.minusBtn.hidden = YES;
            self.textField.hidden = YES;
    
        }
    
}




@end
